<?php
    //
    session_start();
    if(!empty($_SESSION['adminUsername'])){
        echo '<script>window.location.href = "index.php"</script>';
    }
?>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/style.css">
    <style>
        html,body{
            height: 100%;
        }
        body{
            display: flex;
            justify-content: center;
            align-items: center;
            background-image: url("image/login_bg.png");
            background-size: cover;
        }
    </style>
</head>
<body>
<div class="login-div">
    <h1>登录</h1>
    <form id="login-form" action="connect.php" method="post">
        <div class="login-form-item">
            <input name="username" id="username" placeholder="用户名">
        </div>
        <div class="login-form-item">
            <input name="password" id="password" type="password" placeholder="密码">
        </div>
        <button class="btn-login" type="submit">登录</button>
    </form>
</div>
</body>
</html>
<script src="js/jquery-3.5.1.js"></script>
<script src="layui/layui.all.js"></script>
<script src="js/common.js"></script>
<script>

    layuiModules=['layer','form'];

    $(':submit').click(function (){
        $.post('connect.php',{
            type: 'adminLogin',
            username: $('#username').val(),
            password: $('#password').val()
        },function (data){
            if(data === "0"){
                layer.msg('账号或密码输入错误')
            }else if(data === "2"){
                layer.msg('您不是管理员账户')
            }else if(data === "1"){
                window.location.href = 'index.php'
            }else{
                console.log(data)
            }
        })
        return false
    })

</script>